package com.company.cloud.common.log.aspect;


import java.lang.reflect.Method;
import java.util.Date;

import com.alibaba.fastjson.JSON;
import com.alibaba.ttl.internal.javassist.bytecode.SignatureAttribute.MethodSignature;
import com.company.cloud.common.log.annotation.SysLog;
import com.company.cloud.common.log.models.SysLogModel;
import com.company.cloud.common.log.service.SysLogService;
import com.company.cloud.common.utils.HttpContextUtils;



public abstract class SysLogAspect {

	public abstract SysLogService getService();

//	
//	@Pointcut("@annotation(com.company.common.log.annotation.SysLog)")
//	public void logPointCut() {
//		
//	}
//	
//	@Around("logPointCut()")
//	public Object around(ProceedingJoinPoint point) throws Throwable {
//		long beginTime = System.currentTimeMillis();
//		Object result = point.proceed();//执行方法
//		long time = System.currentTimeMillis() - beginTime;//执行时长(毫秒)
//		this.saveSysLog(point, time);//保存日志
//		return result;
//	}
//	
//	
//	private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
//		SysLogModel log=new SysLogModel();
//		MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//		Method method = signature.getMethod();
//		SysLog syslog=method.getAnnotation(SysLog.class);
//		if(syslog!=null) {
//			//描述
//			log.setOperation(syslog.value()); 
//		}
//		//请求的方法名
//		String className=joinPoint.getTarget().getClass().getName();
//		String methodName=signature.getName();
//		log.setMethod(className+"."+methodName+"()");
//		
//		//请求的参数
//		Object[] args=joinPoint.getArgs();
//		if(args!=null && args.length>0) {
//			log.setParams(JSON.toJSONString(args[0]));
//		}
//		
////		LoginUserInfo userInfo= AuthContextUtils.getUserNoValidate();
////		if(userInfo!=null) {
////			log.setUserId(userInfo.getId());
////			log.setUserName(userInfo.getUserName());
////			log.setIp(userInfo.getIp());
////		}else {
////			log.setUserId(0);
////			log.setUserName("anon");
////			log.setIp(HttpContextUtils.getClientIP());
////		}
//		log.setUserAgent(HttpContextUtils.getUA());
//		log.setTime(time);
//		log.setCreateDate(new Date());
//		this.getService().save(log);
//	}
	
	
}
